package com.example.service.entity;

import javax.persistence.*;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Data;
import io.swagger.v3.oas.annotations.media.Schema;

import java.time.LocalDateTime;

/**
 * 用户实体类
 * 用于存储用户的基本信息
 * 
 * @author example
 * @since 1.0.0
 */
@Entity
@Table(name = "system_user")
@Data
@Schema(description = "用户信息实体")
public class User {
    @Schema(description = "用户ID，系统自动生成", example = "1")
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;


    /**
     * 租户
     */
    @Schema(description = "租户")
    @ManyToOne
    @JoinColumn(name = "tenant_id", referencedColumnName = "id")
    private SystemTenant tenant;

    @Schema(description = "用户名，用于登录和显示，必须唯一", example = "admin", requiredMode = Schema.RequiredMode.REQUIRED)
    private String username;

    /**
     * 密码
     */
    @Schema(description = "密码", requiredMode = Schema.RequiredMode.REQUIRED)
    @Column
    @JsonProperty(access = JsonProperty.Access.WRITE_ONLY)
    private String password;


    /**
     * 昵称
     */
    @Schema(description = "昵称")
    @Column
    private String nickname;

    @Schema(description = "用户邮箱，必须唯一", example = "admin@example.com", requiredMode = Schema.RequiredMode.REQUIRED)
    private String email;




    /**
     * 电话
     */
    @Schema(description = "电话")
    @Column
    private String phone;

    /**
     * 姓名
     */
    @Schema(description = "姓名")
    @Column
    private String name;

    /**
     * 账户过期时间
     */
    @Schema(description = "账户过期时间")
    @Column
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    private LocalDateTime accountExpiry;

    /**
     * 最后登录时间
     */
    @Schema(description = "最后登录时间")
    @Column
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    private LocalDateTime lastLogin;

    /**
     * 最后登录客户端信息
     */
    @Schema(description = "最后登录客户端信息")
    @Column
    private String lastAgent;

    /**
     * 最后登录IP
     */
    @Schema(description = "最后登录IP")
    @Column(name = "last_ip")
    private String lastIP;

    /**
     * 登录失败尝试次数
     */
    @Schema(description = "登录失败尝试次数")
    @Column
    private Integer failedAccessAttempts;

    /**
     * 最后登录失败时间
     */
    @Schema(description = "最后登录失败时间")
    @Column
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    private LocalDateTime lastFailedLogin;

    /**
     * 状态 1-正常 2-禁用
     */
    @Schema(description = "状态 1-正常 2-禁用")
    @Column
    private Integer status;

    /**
     * 逻辑删除字段 0-未删除 1-已删除
     */
    @Schema(description = "逻辑删除字段 0-未删除 1-已删除")
    @Column
    private Integer isDeleted;

    /**
     * 创建人
     */
    @Schema(description = "创建人")
    @Column
    private Long createdBy;

    /**
     * 创建时间
     */
    @Schema(description = "创建时间")
    @Column
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    private LocalDateTime createdAt;

    /**
     * 修改人
     */
    @Schema(description = "修改人")
    @Column
    private Long updatedBy;

    /**
     * 修改时间
     */
    @Schema(description = "修改时间")
    @Column
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    private LocalDateTime updatedAt;
} 